package com.joshua.spring.spi;

import com.joshua.spring.entity.vo.GlobalResponse;
import com.joshua.spring.exception.ExceptionErrorDecoder;
import com.joshua.spring.fallback.RestfulRuleClientFallback;
import com.joshua.spring.form.AddDataForm;
import com.joshua.spring.form.QueryRuleInfoForm;
import com.joshua.spring.form.UpdateDataForm;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.joshua.spring.constant.ConsumerApiConstants.RestfulRule.*;
import static com.joshua.spring.constant.ConsumerApiConstants.*;

/**
 * projectName dragon-cloud
 * package com.joshua.spring.spi
 * classname  RestfulRuleClient
 * <p>
 * description
 * </p>
 *
 * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
 * @date 2020/8/31 19:29
 */
@FeignClient(name = APPLICATION_CODE,
        path = CONTEXT_PATH + RULES,
        configuration = {ExceptionErrorDecoder.class},
        fallback = RestfulRuleClientFallback.class)
public interface RestfulRuleClient {
    String PATH_ID = RestfulRule.PATH_ID;

    /**
     * description:
     *
     * @param id
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @GetMapping(PATH_ID)
    GlobalResponse ruleInfo(@PathVariable String id);

    /**
     * description:
     *
     * @param ids
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @GetMapping(ID_ARRAY)
    GlobalResponse queryRuleInfosByIds(@SpringQueryMap String[] ids);

    /**
     * description:
     *
     * @param jsonMap
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @GetMapping(QUERY_MAP)
    GlobalResponse queryRuleInfosByMap(@SpringQueryMap Map jsonMap);

    /**
     * description:
     *
     * @param form
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @GetMapping(QUERY_OBJ)
    GlobalResponse queryRuleInfosByCondition(@SpringQueryMap QueryRuleInfoForm form);

    /**
     * description:
     *
     * @param form
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @PostMapping
    GlobalResponse addData(@RequestBody AddDataForm form);

    /**
     * description:
     *
     * @param id
     * @param form
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @PutMapping(PATH_ID)
    GlobalResponse updateData(@PathVariable Long id, @RequestBody UpdateDataForm form);

    /**
     * description:
     *
     * @param id
     * @return {@link GlobalResponse}
     * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
     * @date 2020/8/31 19:33
     */
    @DeleteMapping(PATH_ID)
    GlobalResponse delData(@PathVariable Long id);
}
